<!doctype html>
<html lang="en" ng-app="app">
<head>
	<base href="${ctx_path}/" />
	<meta charset="UTF-8">
	<title>数据处理</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<script type="text/javascript" src="res/js/jquery-1.10.1.min.js"></script>
	<link rel="stylesheet" href="res/css/function.css"/>
	<link rel="stylesheet" href="res/css/main.css"/>
	<script type="text/javascript" src="res/js/jquery-1.10.1.min.js"></script>
	<script type="text/javascript" src="res/js/jquery-utils.js"></script>
	<script language="javascript" src="res/js/LodopFuncs.js"></script>
	
	<style id="print">
		
		#print_head table{width:100%;font-size:14px;}
		#print_head label{margin-right: 30px;}
		#print_head #print_remark{font-size:12px;margin:5px; padding:5px; border-top:1px dashed ;border-bottom:1px dashed}
		#print_table th, #print_table td{border:1px solid;}
	</style>
	<style>
		#print_head{display:none;}
	</style>
</head>
<body ng-controller="DataController">
	<header>
		<div class="h" style="float:left;border-right:2px dashed #8E9C93;width:25%;">
			<div>
				<input type="file" ng-file-select="onDatasFile($files)" >
			</div>
			<div>
				<button  ng-click="clearData();" class="btn btn-mini btn-green">清空数据</button>
				流水号重置: <input type="checkbox" id="reset_no"><br>
			</div>
			<div>
				<button class="btn btn-mini btn-blue" ng-click="importData();">导入数据</button>
				<a style="text-decoration:none;padding:4px 8px;" class="btn btn-mini btn-grey" href="list/exportData">导出数据</a>
			</div>
		</div>
		<div class="h" style="float:left;padding-left:10px;">
			<div>
			网点名称:<input type="text" style="width:150px;" id="orgName" value="">
			</div>
			<div>
			数量>=<input type="text" id="bnum" style="width:50px;" value="">
			数量<=<input type="text" id="enum" style="width:50px;" value="">
			<button ng-click="search(0);" class="btn btn-mini btn-blue">查询</button>
			</div>
			<div>
			按数量: <button class="btn btn-min btn-red" ng-click="search(0);">升序</button>
				 <button class="btn btn-min btn-blue" ng-click="search(1);">降序</button> 
			</div>
		</div>
		<div class="h" style="float:right;padding-left:10px;border-left:2px dashed #8E9C93;width:25%;">
			<!--  <button ng-click="setup();">编辑 </button>-->
			<div>
			每页的行数:<input type="text" style="width:30px;" id="pageSize" value="45">
			字体:<input type="text" style="width:30px;" id="fontSize" value="14">
			
			</div>
			<div>
			<button class="btn btn-mini btn-grey" ng-click="priview();">预览 </button>
			<button class="btn btn-mini btn-green" ng-click="print();">打印</button>
			<button class="btn btn-mini btn-green" ng-click="print();">暂停打印</button>
			<button class="btn btn-mini btn-green" ng-click="print();">继续打印</button>
			</div>
		</div>
		
		<div class="clearfix"></div>
	</header>
	<div id="print_head">
		<div style="text-align:center;font-size:20px;font-weight:bold;margin:10px;">i保养机滤配送单</div>
		<table>
			<tr><td>配送编号</td><td> {code}</td><td>网点编号</td><td>{dealerCode}</label></td></tr>
			<tr><td>配送公司</td><td> 上海惠保数据科技有限公司</td><td>网点名称</td><td>{orgName} </td></tr>
			<tr><td>地址</td><td> 上海市浦东新区林鸣路177弄A2-2楼</td><td>网点地址</td><td>{filterDealerAddr}</td></tr>
			<tr><td>电话</td><td> 021-60468477</td><td>网点电话</td><td>{orgTel}</td></tr>
			<tr><td>配送单机滤总数  </td><td>{num}</td><td>出库时间</td><td>{currDate}</td></tr>
		</table> 
		<div id="print_remark">
			特别申明<br>
			(1) 收货方收到货物后，请仔细核对配送单与实物的是否一致，如发生不一致情况，请第一时间联系客服人员（电话或者网点群均可）协调处理<br>
			(2) 客户车型选择正确，惠保配送的机滤品牌和型号与车型不适配的，可联系工作人员安排退换货<br>
			(3) 因上述2种原因造成网点退换货的，退货费用由惠保公司承担<br>
			(4) 客户车型选择错误，网点应在点击服务完成前联系惠保工作人员修改为正确的车型和适配机滤型号，避免错发<br>
			(5) 退货时请将2联随货寄回，并在备注栏注明原因，方便工作人员辨别处理<br>
		</div>
	</div>
	<div style="margin:0px 10px;">
		<div class="t-table" style="overflow-x:auto" id="div2">
			<table>
				<thead>
					<tr>
						<th cellpadding="2px" nowrap ng-repeat="column in columns">{{remarks[column]}}</th>
					</tr>
				</thead>
				<tbody>
					<tr ng-repeat="data in datas.list">
						<th ng-repeat="column in columns">{{data[column]}}</th>
					</tr>
				</tbody>
			</table>
			
		</div>
		<pagination page="datas"></pagination>
	</div>
	<div id="loading" style="" class="loaders">
      <div class="loader">
          <div class="loader-inner ball-pulse">
              <div></div><div></div><div></div>
          </div>
      </div>
	</div>
	<script type="text/javascript" src="res/lib/angular.js"></script>
	<script type="text/javascript" src="res/lib/angular-file-upload.min.js"></script>
	<script type="text/javascript">
	var app = angular.module('app', ['ngFileUpload']);
	app.controller('DataController', function($scope, $http, $upload){
		
		// 搜索
		$scope.search = function(sort){
			if(!sort){
				sort = 0;
			}
			var params = {"orgName":$("#orgName").val(), "sort":sort, "bno":$("#bnum").val(), "eno":$("#enum").val()};
			$http({method:'post',
	            url:"list/findAll",
	            params:params
	        }).success(function(result){
	        	if(result.status == 1){
					var option = {page : result.page, url:"list/findAll",params:params};
					$scope.datas = $.handlePage(option);
					$scope.ids = result.ids;
					$scope.columns = result.columns;
					$scope.remarks = result.remarks;
				}else{
					alert(result.msg);
				}
	        }).error(function(){
	            alert("网络连接失败");
	        });
		}
		$scope.search(0);
		// 上传 数据文件
		$scope.onDatasFile = function(files){
	         var file = files[0];
	         if (file == null) return;
	        
	         $scope.upload = $upload.upload({
	             url: "list/uploadData", 
	             file: file, 
	             fileName: file.name 
	         }).progress(function(evt) {        
	         }).success(function(data, status, headers, config) {        
	               alert(data.msg);
	         });   
		 }
		$scope.clearData = function(){
			var params={table_name:'datas'}
			if($("#reset_no").is(":checked")){
				params["reset_no"] = 1;
			}else{
				params["reset_no"] = 0;
			}
			$http({method:'post',
	              url:"list/clearData",
	              params:params
	        }).success(function(result){
	            alert(result.msg);
	            $scope.search(0);
	        }).error(function(){
	            alert("网络连接失败");
	        });
		}
		 // 导入数据
		 $scope.importData = function(){
			if(!confirm("确定是否已经导入excel文件?"))return;
			$http({method:'post',
	              url:"list/importData",
	              params:{table_name:'datas'}
	        }).success(function(result){
	            alert(result.msg);
	        	$scope.search(0);
	        }).error(function(){
	            alert("网络连接失败");
	        });
		 }
		 
		 // 导出数据
		 $scope.exportData = function(){
			 window.location.href = "list/exportData";
			 
		 }
		$scope.setup = function(){
			LODOP=getLodop();  
			LODOP.PRINT_INIT("中文学位证书打印");
			LODOP.ADD_PRINT_TABLE(50,10,"50%",220,document.getElementById("div2").innerHTML);
			LODOP.ADD_PRINT_HTM(2,0,"50%",200,"<body style='margin-top:0'>表格后面用<font color=blue>ADD_PRINT_HTM</font>附加其它备注</body>");
			
			LODOP.SET_PRINT_STYLEA(0,"LinkedItem",-1);		
			LODOP.PRINT_SETUP();
		}
		
		// 打印
		$scope.print = function(){
			if(!$scope.ids){
				alert("请导入数据");return;
			}
			var ids = $scope.ids.split(",");
			print1(0, ids);
			
		}
		
		function print1(orgNo, ids){
			var fontSize = $("#fontSize").val();
			if(!fontSize){
				fontSize = 14;
			}
			var s = "#print_table td{font-size:"+fontSize+"px;}"
			if(ids[orgNo]){
				$http({method:'post',
		            url:"list/print",
		            params:{"pageSize":$("#pageSize").val(), "orgNo":ids[orgNo], "printHead":$("#print_head").html()}
				
		        }).success(function(result){
		        	if(result.status == 1){
		        		LODOP=getLodop();  
		        		LODOP.PRINT_INIT("打印控件Lodop功能演示_多页预览");
		        		//LODOP.SET_PRINT_PAGESIZE(1,500,400,"test");
						var print = angular.fromJson(result.printResult);
						for(var i=0; i<print.totalPage; i++){
							LODOP.NewPage();
							var style = "<style>"+$("#print").html()+"</style>"+"<body style='margin:10px;font-size:"+fontSize+"px'>"
							if(i==0){
								style += print.headers[0]
							}
							style += print.results[i]+"</body>";
							
							LODOP.ADD_PRINT_HTM("0%","0%","100%","100%",style);
						}
						LODOP.PRINT();
						
						print1(++orgNo, ids);
					}else{
						alert(result.msg);
					}
		        }).error(function(){
		            alert("网络连接失败");
		        });
			}else{
				print1(++orgNo, ids);
			}
			
		}
		// 打印预览
		$scope.priview = function(){
			var fontSize = $("#fontSize").val();
			if(!fontSize){
				fontSize = 14;
			}
			var s = "#print_table td{font-size:"+fontSize+"px;}";
			var data = $scope.datas.list[0];
			if(!data){
				alert("请先导入数据");return;
			}
			data["printHead"] = $("#print_head").html();
			$http({method:'post',
	            url:"list/findByCode",
	            params:{"data":data, "pageSize":$("#pageSize").val()}
	        }).success(function(result){
	        	if(result.status == 1){
	        		LODOP=getLodop();  
	        		LODOP.PRINT_INIT("打印控件Lodop功能演示_多页预览");
	        		//LODOP.SET_PRINT_PAGESIZE(1,500,400,"test");
					var print = angular.fromJson(result.printResult);
					for(var i=0; i<print.totalPage; i++){
						LODOP.NewPage();
						var style = "<style>"+$("#print").html()+s+"</style>"+"<body style='margin:10px;'>"
						if(i==0){
							style += print.headers[0]
						}
						style += print.results[i]+"</body>";
						
						LODOP.ADD_PRINT_HTM("0%","0%","100%","100%",style);
					}
					LODOP.PREVIEW();
				}else{
					alert(result.msg);
				}
	        }).error(function(){
	            alert("网络连接失败");
	        });
					
		 }
		 
	});
	app.directive('pagination', ['$http',function($http){
		return Common.pagination($http);
	}]);
	app.factory('myInterceptor', function(){		
		return Common.requestInterceptor;
	});
	
	app.config(['$httpProvider', function($httpProvider) {
	    $httpProvider.interceptors.push('myInterceptor');
	}]);
	</script>	
</body>
</html>